class Solution {
public:
    double quickMul(double x, long long N) {
        if (N == 0) return 1.0;
        double ans = 1.0;
        double x_contribute = x;

        while (N > 0) {
            if (N % 2 == 1) ans *= x_contribute;
            x_contribute *= x_contribute;
            N /= 2;
        }
        return ans;
    }

    double myPow(double x, int n) {
        if (x == 0) return 0;
        if (n == 0) return 1;
        long long N = n;
        return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N);
    }
};